using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 权限路由映射实体 - 数据库存储版本
    /// 支持运行时热更新和集中管理
    /// </summary>
    [Table("permission_route_mappings")]
    public class PermissionRouteMapping : ITenantEntity
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        [Key]
        public long Id { get; set; }
        
        /// <summary>
        /// 路径模式，支持通配符 * 和 **
        /// 例如：/api/users/**, /api/content/*/items
        /// </summary>
        [Required]
        [StringLength(500)]
        public string Path { get; set; } = string.Empty;
        
        /// <summary>
        /// HTTP方法
        /// GET, POST, PUT, DELETE, PATCH 等
        /// </summary>
        [Required]
        [StringLength(10)]
        public string Method { get; set; } = string.Empty;
        
        /// <summary>
        /// 对应的权限代码
        /// </summary>
        [Required]
        [StringLength(100)]
        public string PermissionCode { get; set; } = string.Empty;
        
        /// <summary>
        /// 映射名称/描述
        /// </summary>
        [StringLength(200)]
        public string? Name { get; set; }
        
        /// <summary>
        /// 详细描述
        /// </summary>
        [Column(TypeName = "text")]
        public string? Description { get; set; }
        
        /// <summary>
        /// 优先级（数字越小优先级越高）
        /// </summary>
        public int Priority { get; set; } = 0;
        
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;
        
        /// <summary>
        /// 映射来源：Database, Configuration, System
        /// </summary>
        [StringLength(50)]
        public string Source { get; set; } = "Database";
        
        /// <summary>
        /// 分组/模块
        /// </summary>
        [StringLength(100)]
        public string? Group { get; set; }
        
        /// <summary>
        /// 排序权重
        /// </summary>
        public int SortOrder { get; set; } = 0;
        
        /// <summary>
        /// 备注
        /// </summary>
        [Column(TypeName = "text")]
        public string? Remark { get; set; }
        
        /// <summary>
        /// 创建人ID
        /// </summary>
        public long? CreatedBy { get; set; }
        
        /// <summary>
        /// 更新人ID
        /// </summary>
        public long? UpdatedBy { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 扩展属性（JSON格式）
        /// 可存储额外配置如：条件判断、参数校验等
        /// </summary>
        [Column(TypeName = "json")]
        public string? ExtendedProperties { get; set; }

        // 导航属性
        /// <summary>
        /// 创建人
        /// </summary>
        [ForeignKey(nameof(CreatedBy))]
        public User? Creator { get; set; }
        
        /// <summary>
        /// 更新人
        /// </summary>
        [ForeignKey(nameof(UpdatedBy))]
        public User? Updater { get; set; }

        /// <summary>
        /// 租户标识符
        /// </summary>
        public string TenantId { get; set; } = string.Empty;
    }
}
